package com.csm.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.commons.dao.BaseDao;
import com.commons.po.StatusMsg;
import com.csm.dao.StatusmsgDao;

public class StatusmsgDaoImpl extends BaseDao<StatusMsg> implements StatusmsgDao {
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	@Override
	public List<StatusMsg> queryAll() {
		List<StatusMsg> list = new ArrayList<StatusMsg>();
		String sql = "select * from statusmsg";
		conn = getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while(rs.next()){
				StatusMsg sm = new StatusMsg();
				sm.setId(rs.getInt(1));
				sm.setCustomer_password(rs.getString(2));
				sm.setCreated_id(rs.getInt(3));
				sm.setCreated_date(rs.getDate(4));
				sm.setUpdated_id(rs.getInt(5));
				sm.setUpdated_date(rs.getDate(6));
				sm.setIs_active(rs.getInt(7));
				list.add(sm);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	@Override
	public boolean saveStatusMsg(StatusMsg user){
		boolean isFlag = false;
		String sql = "insert into statusmsg values (?,?,?,?,?,?,?)";
		conn = getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, user.getId());
			pstmt.setString(2, user.getCustomer_password());
			pstmt.setInt(3, user.getCreated_id());
			pstmt.setDate(4, user.getCreated_date());
			pstmt.setInt(5, user.getUpdated_id());
			pstmt.setDate(6, user.getUpdated_date());
			pstmt.setInt(7, user.getIs_active());
			int num = pstmt.executeUpdate();
			if(num!=0){
				isFlag=true;
			}
			return isFlag;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	@Override
	public StatusMsg getEntity(ResultSet rs) {
		// TODO Auto-generated method stub
		return null;
	}
	
}
